﻿using UnityEngine;
using System.Collections;

public class EnemyCollider : MonoBehaviour {

    public int hitPoints = 3;
    public int damage = 1;

    void OnCollisionEnter(Collision coll)
    {
        
        PlayerCollider player = coll.gameObject.GetComponent<PlayerCollider>();
        if (player != null)
        {
            transform.Translate(Vector3.forward); //dummy push to the front so he can collide again
            player.TakeDamage(damage);
        }


    }

    public void TakeDamage(int damage)
    {
        hitPoints -= damage;
        if (hitPoints < 1)
        {
            DestroyObject(gameObject);
        }
    }
}
